//
//  DDDADSDKAppDelegate.m
//  DDDAdSdk
//
//  Created by summerthread on 09/18/2020.
//  Copyright (c) 2020 summerthread. All rights reserved.
//

#import "DDDADSDKAppDelegate.h"
#import "DDDADSDKViewController.h"
#import <DDDAdSdk/DDDAdSdk.h>

@interface DDDADSDKAppDelegate ()<DDDSplashAdViewDelegate>
@property (nonatomic,strong) UIView *adBackView;
@property (nonatomic,strong) DDDSplashAdView *splashView;
@end

@implementation DDDADSDKAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    [[DDDAdSdkManager shareInstance] configSetSDKWithUserId:@""];//
    [DDDAdGameManager configSetAdGameResult:^(NSInteger resultCode) {
        if (resultCode == 0) {
            NSLog(@"初始化成功");
        } else {
            NSLog(@"初始化失败--%ld",resultCode);
        }
    }];
    [DDDSportGameManager configSetSportGameResult:^(NSInteger resultCode) {
        if (resultCode == 0) {
            NSLog(@"互动广告初始化成功");
        } else {
            NSLog(@"互动广告初始化失败--%ld",resultCode);
        }
    }];
    
    UIWindow *window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    UINavigationController *nvc = [[UINavigationController alloc]initWithRootViewController:[[DDDADSDKViewController alloc]init]];
    window.rootViewController = nvc;
    [window makeKeyAndVisible];
    self.window = window;
    
    [self addSplashAD];
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (void)addSplashAD {
    
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    CGFloat height = [UIScreen mainScreen].bounds.size.height - 120.0;
    
    DDDSplashAdView *splashView = [[DDDSplashAdView alloc]initWithFrame:CGRectMake(0.0, 0.0, width, height) andRootWindow:self.window andTolerateTimeout:5 andHideSkipButton:NO];
    splashView.delegate = self;
    self.splashView = splashView;
    
}

#pragma mark - DDDSplashAdViewDelegate
/// 素材加载成功时候的回调
/// @param splashAd splashAd
- (void)splashAdDidLoad:(DDDSplashAdView *)splashAd {
    NSLog(@"%s",__func__);
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0.0, [UIScreen mainScreen].bounds.size.height - 120.0, [UIScreen mainScreen].bounds.size.width, 120.0)];
    backView.backgroundColor = [UIColor redColor];
    [self.splashView showAdWithBottomView:backView];
}
- (void)splashAdDidClose:(DDDSplashAdView *)splashAd {
    [splashAd removeFromSuperview];
    [self.adBackView removeFromSuperview];
}

- (void)splashAd:(DDDSplashAdView *)splashAd didFailWithError:(NSInteger)errorCode {
    [splashAd removeFromSuperview];
    [self.adBackView removeFromSuperview];
    NSLog(@"summer--error--%ld",errorCode);
}

- (void)splashAdWillVisible:(DDDSplashAdView *)splashAd {
    
}

@end
